﻿//============================================================
//write by bxl at 2021-06-12 15:56:29
//============================================================



using System.Collections.Generic;
using System;
using BCService.Utils;
using BCCommon;
using BCData.TMS.Order.OrderGoodsChecklist;
using BCDto.TMS.Order.OrderGoodsChecklist;
using BCEntity.TMS.Order.OrderGoodsChecklist;
using BCDto.Sim.Admin.Admin;

namespace BCService.TMS.Order.OrderGoodsChecklist
{
    public class OrderGoodsChecklistService : IOrderGoodsChecklistService
    {
        #region var
        private readonly IDatabaseContext databaseContext;
        private IOrderGoodsChecklistData orderGoodsChecklistData;


        #endregion

        #region 构造函数
        public OrderGoodsChecklistService(IOrderGoodsChecklistData orderGoodsChecklistData, IDatabaseContext databaseContext)
        {
            this.orderGoodsChecklistData = orderGoodsChecklistData;
            this.databaseContext = databaseContext;
        }
        #endregion

        #region Add
        /// <summary>
        /// 添加新订单货物清单纪录
        /// </summary>
        /// <param name="orderGoodsChecklistRequestDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public OrderGoodsChecklistDto Add(OrderGoodsChecklistRequestDto orderGoodsChecklistRequestDto, AdminDto admin)
        {
            return orderGoodsChecklistData.InsertAsync(orderGoodsChecklistRequestDto.As<OrderGoodsChecklistEntity>()).GetAwaiter().GetResult().As<OrderGoodsChecklistDto>();
        }
        #endregion

        #region update
        /// <summary>
        /// 修改订单货物清单记录
        /// </summary>
        /// <param name="orderGoodsChecklistDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public OrderGoodsChecklistDto Update(OrderGoodsChecklistDto orderGoodsChecklistDto, AdminDto admin)
        {
            return orderGoodsChecklistData.UpdateAsync(orderGoodsChecklistDto.As<OrderGoodsChecklistEntity>()).GetAwaiter().GetResult().As<OrderGoodsChecklistDto>();

        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除订单货物清单记录
        /// </summary>
        /// <param name="orderGoodsChecklistId"></param>
        /// <returns></returns>
        public void Delete(long orderGoodsChecklistId)
        {
            orderGoodsChecklistData.DeleteAsync(orderGoodsChecklistId).GetAwaiter().GetResult();

        }
        #endregion

        #region GetByOrderGoodsChecklistId
        /// <summary>
        /// 获取订单货物清单记录
        /// </summary>
        /// <param name="orderGoodsChecklistId"></param>
        /// <returns></returns>
        public OrderGoodsChecklistDto GetById(long orderGoodsChecklistId)
        {
            var a = orderGoodsChecklistData.GetEntityAsync(orderGoodsChecklistId).GetAwaiter().GetResult();
            return a.As<OrderGoodsChecklistDto>();
        }
        #endregion

        #region GetList  获取订单货物清单记录--[分页]
        public PageableList<OrderGoodsChecklistDto> GetList(int pageIndex, int pageSize)
        {
            int fCount = 0;
            IEnumerable<OrderGoodsChecklistEntity> fList;

            (fList, fCount) = orderGoodsChecklistData.GetListAsync(pageIndex, pageSize).GetAwaiter().GetResult();

            return new PageableList<OrderGoodsChecklistDto>()
            {
                Count = fCount,
                Items = fList.As<IEnumerable<OrderGoodsChecklistDto>>(),
                PageIndex = pageIndex,
                PageSize = pageSize,
                ServerTime = DateTime.Now,
            };
        }
        #endregion
    }
}